<?php

class Article_Modele extends Modele
{
	private $_id;
	private $_title;
	private $_url_title;
	private $_description;
	private $_keywords;
	private $_content;
	private $_creation_date;
	private $_update_date;
	private $_isPublished;
	private $_categorieId;
	
	
	static public function getRef($id, $title, $url_title, $description, $keywords, $content, $creation_date, $update_date, $isPublished, $categorieId)
	{
		return new Article_Modele($id, $title, $url_title, $description, $keywords, $content, $creation_date, $update_date, $isPublished, $categorieId);
	}	
	
	
	public function Article_Modele($id, $title, $url_title, $description, $keywords, $content, $creation_date, $update_date, $isPublished, $categorieId)
	{
		parent::Modele("article","id");
		$this->_id = $id;
		$this->_title = $title;
		$this->_url_title = $url_title;
		$this->_description = $description;
		$this->_keywords = $keywords;
		$this->_content = $content;
		$this->_creation_date = $creation_date;
		$this->_update_date = $update_date;
		$this->_isPublished = $isPublished;
		//$this->_isSharable = $isSharable;
		$this->_categorieId = $categorieId;
		
		// Recherche des traduction
		/*$req = "select * from cl_translate where fr_article = ".$this->_id.";";
		$sql = new SQLAdapt();
		$res = $sql->query($req);
		if($res && $res->rowCount() > 0)
		{
			//$res = $res->fetch();
			foreach($res as $r)
			{
				$lang = $r[5];
				$this->_translate[$lang] = array(
					$r[1], // titre
					$r[2], // mot clef
					$r[3], // description
					$r[4]  // content
				);
			}
		}
		else
			$this->_translate = null;*/
	}
	
	public function isAvaible()
	{
		//if($this->_translate[$_SESSION['lang']] == null && $_SESSION['lang'] != 'fr')
		//	return false;
	/*	else
			return true;*/
	}
	
	public function get_lang_date_edition($lang)
	{	
		$str = explode(' ', $this->_creation_date);
		$date = $str[0];
		$hour = $str[1];
		$date = explode('-', $date);
		$hour = explode(':', $hour);
		switch($lang)
		{
			case 'fr':
				return $date[2].'/'.$date[1].'/'.$date[0].' à  '.$hour[0].'h'.$hour[1];
				break;
			/*case 'en':
				return $date[1].'-'.$date[2].'-'.$date[0].' at '.$hour[0].':'.$hour[1];*/
				break;
		}
	}
	
	public function get_lang_update_date($lang)
	{	
		$str = explode(' ', $this->_update_date);
		$date = $str[0];
		$hour = $str[1];
		$date = explode('-', $date);
		$hour = explode(':', $hour);
		switch($lang)
		{
			case 'fr':
				return $date[2].'/'.$date[1].'/'.$date[0].' Ã  '.$hour[0].'h'.$hour[1];
				break;
			/*case 'en':
				return $date[1].'-'.$date[2].'-'.$date[0].' at '.$hour[0].':'.$hour[1];*/
				break;
		}
		
	}
	
	public function get_id()
	{
		return $this->_id;
	}
	
	public function get_title()
	{
			return $this->_title;
	}
	
	public function get_url_title()
	{
		return $this->_url_title;
	}
	
	public function get_lang_url_title()
	{
		$url = $this->_url_title;
	}
	
	public function get_fr_url_title()
	{
		$url = $this->_url_title;
	}
	
	public function get_description()
	{
			return $this->_description;
	}
	
	public function get_keywords()
	{
			return $this->_keywords;
	}
	
	public function get_content()
	{
			return $this->_content;
	}
	
	public function get_creation_date()
	{
		return $this->_creation_date;
	}
	
	public function get_update_date()
	{
		return $this->_update_date;
	}
	
	public function get_isPublished()
	{
		return $this->_isPublished;
	}
	
	public function get_categorieId()
	{
		return $this->_categorieId;
	}
	
	public function get_categorie_name()
	{
		$adapt = new SQLAdapt();
		$req = "select name from categorie where id = ".$this->_categorieId;
		$res = $adapt->query($req);
		$res = $res->fetch();
		/*return Lang::TRANSLATE($res[0]);*/
		return $res[0];
		
	}
	
	public function get_color_value()
	{
		$adapt = new SQLAdapt();
		$req = "select hexa from color col, categorie cat where cat.colorId = col.id and cat.id = ".$this->_categorieId;
		$res = $adapt->query($req);
		$res = $res->fetch();
		return $res[0];
	}
	
	public function is_new()
	{
		// Ajout d'un semaine à la date de création
		$dateTmp = strtotime($this->_creation_date);
		$dateTmp = date("Y-m-d", mktime(0, 0, 0,
			date('m', $dateTmp),
			date('d', $dateTmp) + 7,
			date('Y', $dateTmp)));
		
		// Formattage des deux dates pour les comparer
		$dateC = str_replace('-', '', $dateTmp);
		$dateN = str_replace('-', '', date("Y-m-d"));
		
		// Comparaison
		if($dateC > $dateN)
			return true;
		
		return false;
		
	}
	
	// Commutateur
	public function set_title($v)
	{
		$this->_title = $v;
	}
	
	public function set_url_title($v)
	{
		$this->_url_title = $v;
	}
	
	public function set_description($v)
	{
		$this->_description = $v;
	}
	
	public function set_keywords($v)
	{
		$this->_keywords = $v;
	}
	
	public function set_content($v)
	{
		$this->_content = $v;
	}
	
	public function set_update_date($v)
	{
		$this->_update_date = $v;
	}
	
	public function set_isPublished($v)
	{
		if($v != "" && $v != null)
			$this->_isPublished = 1;
		else
			$this->_isPublished = 0;
	}
	
	public function set_categorieId($v)
	{
		$this->_categorieId = $v;
	}
}

?>
